package com.lib.torment.androidlib.core;

import android.app.Activity;

import com.lib.torment.androidlib.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity管理类
 */
public class ActivityManager {
    private static final String TAG = "ActivityManager";

    private static ActivityManager instance;

    private List<Activity> activityList = new ArrayList<Activity>();

    private ActivityManager() {
    }

    public synchronized static ActivityManager getInstance() {
        if (instance == null) {
            instance = new ActivityManager();
        }

        return instance;
    }

    public void addActivity(Activity activity) {
        activityList.add(activity);
    }

    public void removeActivity(Activity activity) {
        if (activity != null) {
            activityList.remove(activity);
        }
    }

    public boolean isActivityExist(String activityClassName) {
        if (activityClassName == null) {
            return false;
        }

        for (Activity activity : activityList) {
            String shorClassName = activity.getComponentName().getClassName();
            LogUtils.debug(TAG, shorClassName);

            if (shorClassName.equals(activityClassName)) {
                return true;
            }
        }

        return false;
    }

    public void exitAllActivity() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }

}
